package sensorgui;

/**
 * Very simple class to encapsulate the concept of the four compass points.
 */
public class Direction {
	
	private double value;
	
	/**
	 * Construct a Direction with the given angle, measured clockwise from north
	 * @param value in radians
	 */
	public Direction(double value) {
		this.setValue(value);
	}
	
	public double getValue() {
		return value;
	}
	
	public void setValue(double value) {
		// TODO: find a way to prevent a setValue on any of the static final directions
		// Only allow values between 0 and 2 pi
		value %= (360);
		if (value < 0) value += (360);
		this.value = value;
	}

	public boolean equals(Direction other) {
		double difference = Math.abs(other.getValue() - value);
		// Now make sure difference is less than the required accuracy
		// TODO: remove dependency between Direction and TurnTask.stepSize
		if (difference == 0) return true;
		else return false;
	}
	
	public String toString() {
		// 
		if (value == SensorConstants.north) return "North";
		else if (value == SensorConstants.east) return "East";
		else if (value == SensorConstants.south) return "South";
		else if (value == SensorConstants.west) return "West";
                else if (value == SensorConstants.northwest) return "NorthWest";
                else if (value == SensorConstants.northeast) return "NorthEast";
                else if (value == SensorConstants.southwest) return "SouthWest";
                else if (value == SensorConstants.southeast) return "SouthEast";
		else return "Unknown";
	}
	
	/**
	 * Returns an all-lower-case text representation of this direction.
	 * Clients can rely on this, unlike toString, which is for debug output and printing only.
	 */
	public String toName() {
		// 
		if (value == SensorConstants.north) return "north";
		else if (value == SensorConstants.east) return "east";
		else if (value == SensorConstants.south) return "south";
		else if (value == SensorConstants.west) return "west";
                else if (value == SensorConstants.northwest) return "northwest";
                else if (value == SensorConstants.northeast) return "northeast";
                else if (value == SensorConstants.southwest) return "southwest";
                else if (value == SensorConstants.southeast) return "southeast";
		else return "Unknown";
	}

        
	

}
